import Common from "../Common/Common";
import BaseUI from "../core/BaseUI";
import DataManager from "../core/DataManager";
import DataStorage from "../core/DataStorage";
import ResourcesManager from "../core/ResourcesManager";
import UIManager from "../core/UIManager";
const hall= cc.Class({
    extends: BaseUI,

    properties: {
        level:{
            default: null,
            type: cc.Label,
            tooltip: '关卡' 
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    onLoad() {
        this.toggle_wx = this.node.getChildByName('wx_toggle').getComponent(cc.Toggle);
    },
    start () {
   
    },
    wx_yh(){
        if(cc.sys.ANDROID)
        if (cc.sys.platform == cc.sys.ANDROID) {
            console.log("wx_yh");
            
            jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "openXieYi", "()V");
        }
    },

    wx_ys(){

        console.log("wx_ys");
        
        if (cc.sys.platform == cc.sys.ANDROID) {
            
            jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "openYinSi", "()V");
        }
    },
    
    open() {
        this._super(arguments);
        // httpUtils.httpPost(consts.HTTP_RECORD_SERVER,{title:'首页',content:'访问',desc:null},function(respone){});
        Common.startTouchTime = new Date().getTime();
        DataManager.currLevel = DataStorage.getlocalData().level;
        DataManager.getCurrLevelConfig("DinosaurConfig", DataManager.currLevel);
        this.level.string = "LEVEL " + DataManager.currLevel // DataManager.GameConfig["DinosaurLevel"][DataManager.currLevel].name;
        if (appGame.platform != "chuanyinGame")
            DataManager.showBannerAd();

        this.timeOutID1212 = setTimeout(() => {
            DataManager.showInterAd();
        }, 2000);
    },

    close() {
        this._super(arguments);
        this.timeOutID1212&&clearTimeout(this.timeOutID1212)
    },

    /**点击游戏开始 */
    onClickGameStart(event) {
        console.log(this.toggle_wx.isChecked);
        if (this.toggle_wx.isChecked) {

            this.close();
        

            // //初始本局音乐顺序
            // DataStorage.initStorage();
            // //设置当前关卡数
            // DataManager.currLevel = DataStorage.localData.level;
            // console.log(DataStorage.localData);
            UIManager.instance.load.open();
            if (DataManager.GameConfig[DataManager.currLevel]) {
                UIManager.instance.load.close();
                UIManager.instance.game.open();
            } else {
                ResourcesManager.loadAtlas("res/" + DataManager.GameConfig["DinosaurLevel"][DataManager.currLevel].type,
                    (data, pathName) => {
                        DataManager.GameConfig[DataManager.currLevel] = Common.arraytoJson(data, "name");
                        UIManager.instance.load.close();
                        UIManager.instance.game.open();
                    });
    
            }

        }else{
            if (cc.sys.platform == cc.sys.ANDROID) {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "showTip", "()V");
            }
        }


        // this.close();
        

        // //初始本局音乐顺序
        // DataStorage.initStorage();
        // //设置当前关卡数
        // DataManager.currLevel = DataStorage.localData.level;
        // console.log(DataStorage.localData);
        // UIManager.instance.load.open();
        // if (DataManager.GameConfig[DataManager.currLevel]) {
        //     UIManager.instance.load.close();
        //     UIManager.instance.game.open();
        // } else {
        //     ResourcesManager.loadAtlas("res/" + DataManager.GameConfig["DinosaurLevel"][DataManager.currLevel].type,
        //         (data, pathName) => {
        //             DataManager.GameConfig[DataManager.currLevel] = Common.arraytoJson(data, "name");
        //             UIManager.instance.load.close();
        //             UIManager.instance.game.open();
        //         });

        // }

    
        // httpUtils.httpPost(consts.HTTP_RECORD_SERVER, { title: '开始游戏', content: '点击', desc: null }, function () {});
    },
    // update (dt) {},
});

export default hall;